package service.book;

import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;

import dao.book.BookTypeDao;
import dao.book.BookTypeDaoImpl;
import entity.BookType;
import utils.SqlConnection;

/**
 * @Author: Lin Hongwei
 * @LastEditors: Lin Hongwei
 * @email: 1365755396@qq.com
 * @CSDN: https://blog.csdn.net/weixin_45429409
 * @Description: 
 *
 */
public class BookTypeServerImpl implements BookTypeServer {
	Connection connection;
	BookTypeDao bookTypeDao = new BookTypeDaoImpl();
	BookType bookType = null;

	@Override
	public boolean addBookType(BookType bookType) {
		// TODO Auto-generated method stub
		connection = SqlConnection.getConnection();
		int row = 0;
		try {
			row = bookTypeDao.addBookType(connection, bookType);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return row > 0;
	}

	@Override
	public List<BookType> getBookTypeList(BookType bookType) {
		// TODO Auto-generated method stub
		if(bookType==null)bookType = new BookType();
		connection = SqlConnection.getConnection();
		ArrayList<BookType> bookTypeList = new ArrayList<BookType>();
		try {
			bookTypeList = (ArrayList<BookType>) bookTypeDao.getBookTypeList(connection, bookType);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return bookTypeList;
	}

	@Override
	public boolean upBookType(BookType bookType) {
		// TODO Auto-generated method stub

		if (bookType == null)
			bookType = new BookType();
		connection = SqlConnection.getConnection();
		int row = 0;
		try {
			row = bookTypeDao.upBookType(connection, bookType);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return row > 0;
	}

	@Override
	public boolean deleteBookType(int id) {
		// TODO Auto-generated method stub
		connection = SqlConnection.getConnection();

		int row = 0;

		try {
			row = bookTypeDao.delBookType(connection, id);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return row > 0;
	}

}
